<template>

	<div id="map" style="margin:0 auto;width: 100%;height: 100%;"></div>

</template>

<script>
	import L from "leaflet";
	import proj4 from "proj4";
	import proj4leaflet from "proj4leaflet";
	import 'leaflet/dist/leaflet.css'
	var esri = require("esri-leaflet");
	// esri.basemapLayer("Topographic").addTo(this.map);
	delete L.Icon.Default.prototype._getIconUrl;
	L.Icon.Default.mergeOptions({
		iconRetinaUrl: require("leaflet/dist/images/marker-icon-2x.png"),
		iconUrl: require("leaflet/dist/images/marker-icon.png"),
		//iconUrl: require('../assets/images/1.png'),
		shadowUrl: require("leaflet/dist/images/marker-shadow.png")
	});
	export default {
		data() {
			return {
	
			};
		},
		mounted() {
			this.initDate();
		},
		methods: {
			initDate() {
				let CRS_4490 = new L.Proj.CRS(
					"EPSG:4490",
					"+proj=longlat +ellps=GRS80 +no_defs", {
						resolutions: [
							//1.40625,
							0.703125,
							0.3515625,
							0.17578125,
							0.087890625,
							0.0439453125,
							0.02197265625,
							0.010986328125,
							0.0054931640625,
							0.00274658203125,
							0.001373291015625,
							6.866455078125e-4,
							3.4332275390625e-4,
							1.71661376953125e-4,
							8.58306884765625e-5,
							4.291534423828125e-5,
							2.1457672119140625e-5,
							1.0728836059570312e-5,
							5.364418029785156e-6,
							2.682209064925356e-6,
							1.3411045324626732e-6
						],
						origin: [-180, 90]
						//bounds: L.bounds([70.92773, 18.14585], [170.94727, 47.15984])
						//这里可以有origin、transformation、scales、resulutions、bounds几个参数提供
						//选择，其中scales与resolutions不能同时配置
					}
				);
	
				var normalMapm = L.tileLayer(
					"http://t0.tianditu.com/vec_c/wmts?layer=vec&style=default&tilematrixset=c&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}&tk=ac0daf56728bbb77d9514ba3df69bcd3", {
						maxZoom: 19,
						minZoom: 0,
						zoomOffset: 1,
						detectRetina:true
					}
				);
				var normalMapa = L.tileLayer(
					"http://t0.tianditu.gov.cn/cva_c/wmts?layer=cva&style=default&tilematrixset=c&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}&tk=ac0daf56728bbb77d9514ba3df69bcd3", {
						maxZoom: 19,
						minZoom: 0,
						zoomOffset: 1,
						detectRetina:true
					}
				);
	
				var imgMapm = L.tileLayer(
					"http://t0.tianditu.gov.cn/img_c/wmts?layer=img&style=default&tilematrixset=c&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}&tk=ac0daf56728bbb77d9514ba3df69bcd3", {
						maxZoom: 19,
						minZoom: 0,
						zoomOffset: 1,
						detectRetina:true
					}
				);
				var imgMapa = L.tileLayer(
					"http://t0.tianditu.gov.cn/cia_c/wmts?layer=cia&style=default&tilematrixset=c&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}&tk=ac0daf56728bbb77d9514ba3df69bcd3", {
						maxZoom: 19,
						minZoom: 0,
						zoomOffset: 1,
						detectRetina:true
					}
				);
				var normalMap = L.layerGroup([normalMapm, normalMapa]).setZIndex(100),
					imgMap = L.layerGroup([imgMapm, imgMapa]).setZIndex(100);
				var baseLayers = {
					卫星: imgMap,
					行政: normalMap
				};
	
				//var map = L.map(this.mapDiv, {
				//    crs: L.CRS.EPSG4326,
				//    center: [51.505, -0.09],
				//    zoom: 12,
				//    layers: [imgMap],
				//    zoomControl: true
				//});
	
				var map = L.map('map', {
					zoomControl: false,
					layers: [normalMap],
					crs: CRS_4490,
					id: new Date().getTime(),
					attributionControl: false,
					trackResize:false
					//center: [28.849348795193773, 108.76430280644045]
				}).setView([28.74, 109.14], 13); //fitWorld();
				var layerControlOptions = {
					hideSingleBase: true,
					autoZIndex: true,
					sortLayers: true,
					sortFunction: function(layerA, layerB, nameA, nameB) {
						[nameA, nameB].sort();
					}
				};
				L.control.layers(baseLayers, null, layerControlOptions).addTo(map);
				L.control.scale().addTo(map);
				var usaDynamicLayer = esri.dynamicMapLayer({
					// url: 'http://localhost:6080/arcgis/rest/services/XiuShan/XiuShanMapService/MapServer',
					//url: '/arcgis/rest/services/XiuShan/XiuShanMapService/MapServer',、
					url: '/serverapi/arcgis/rest/services/XiuShan/XiuShanMapService/MapServer',
					f:'image',
					opacity: 1
				}).addTo(map);
				// var map = new L.Map('map').setView([45.543, -122.621], 5);
				// esri.basemapLayer('Gray').addTo(map);
				// var service = L.esri.mapService({
				//   url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer'
				// });
	
				//   this.map.removeLayer(name)  // 移除图层
			}
		}
	}
</script>

<style>
</style>
